package tagdb.model;

import tagdb.algorithm.tag.Tag;
import tagdb.denovo.DenovoHit;
import tagdb.io.MascotGenericFile;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <b>ResultSet</b>
 * <p>
 * This class contains information about results from a performed resources-novo search.
 * </p>
 *
 * @author Thilo Muth
 */
public class DenovoSearchResult implements Result {
    /**
     * Holds the results map for the resources-novo hits.
     */
    private Map<String, List<DenovoHit>> resultsMap;

    /**
     * Holds the query spectra.
     */
    private Map<String, MascotGenericFile> querySpectra;

    /**
     * Holds the map for the generated tags.
     */
    private Map<String, List<Tag>> tagMap;

    /**
     * The input filename.
     */
    private String filename;

    /**
     * A result set holds the query spectra and the corresponding resources-novo results.
     *
     * @param querySpectra The query spectra.
     * @param resultsMap   The results map for the resources-novo hits.
     */
    public DenovoSearchResult(Map<String, MascotGenericFile> querySpectra, Map<String, List<DenovoHit>> resultsMap, Map<String, List<Tag>> tagMap, String filename) {
        this.resultsMap = resultsMap;
        this.tagMap = tagMap;
        this.querySpectra = querySpectra;
        this.filename = filename;
    }

    /**
     * Returns list of the denovo hits for a spectrum.
     *
     * @return Denovo hit list.
     */
    public List<DenovoHit> getHits(String spectrumName) {
        return resultsMap.get(spectrumName);
    }

    /**
     * Returns list of the generated tags for a spectrum.
     *
     * @return Tag list.
     */
    public List<Tag> getTags(String spectrumName) {
        return tagMap.get(spectrumName);
    }

    /**
     * Returns the query spectra names.
     *
     * @return Query spectra names
     */
    public List<String> getQuerySpectraNames() {
        return new ArrayList<String>(querySpectra.keySet());
    }

    /**
     * Returns a specific spectrum retrieved by its spectrum name.
     * @param spectrumName The spectrum name.
     * @return Specific spectrum
     */
    public MascotGenericFile getQuerySpectrum(String spectrumName) {
        return querySpectra.get(spectrumName);
    }

    /**
     * Returns the query spectra.
     *
     * @return the querySpectra
     */
    public List<MascotGenericFile> getQuerySpectra() {
        return new ArrayList<MascotGenericFile>(querySpectra.values());
    }

    /**
     * Returns the file name.
     *
     * @return The input file name.
     */
    public String getFilename() {
        return filename;
    }

    @Override
    public Map<String, List<DenovoHit>> getResultMap() {
        return resultsMap;
    }

    /**
     * The size of the denovo search result.
     * @return DenovoSearchResult size.
     */
    public int size() {
        return querySpectra.size();
    }
}
